/*
 * Copyright (c) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// Autogenerated file -- DO NOT EDIT!

#ifndef CORE_ANY_INTRINSICS_INL
#define CORE_ANY_INTRINSICS_INL

<%= Common::include_plugin_files "any", "handlers_path" %>

namespace ark::intrinsics {
ObjectHeader *AnyLdbyname([[maybe_unused]] ManagedThread *thread, [[maybe_unused]] Frame *frame, ObjectHeader *thisObj,
                          [[maybe_unused]] uint32_t id)
{
    if (thisObj == nullptr) {
        interpreter::RuntimeInterface::ThrowNullPointerException();
        return nullptr;
    }
    auto *cls = thisObj->ClassAddr<Class>();
    ASSERT(cls != nullptr);
    [[maybe_unused]] auto pf = frame->GetMethod()->GetPandaFile();
    switch (cls->GetSourceLang()) {
% Common::plugins.each_value do |plugin_opts|
        case <%= plugin_opts["lang_enum"] %>:
% if plugin_opts.include?('any')
            return <%= plugin_opts["directive_name"].upcase %>AnyLdbyname(thread, thisObj,
                pf->GetStringData(panda_file::File::EntityId(id)));
% else
            // Any handlers unimplemented for plugin
            UNREACHABLE();
% end
            break;
% end
        default:
            UNREACHABLE();
    }
}

void AnyStbyname([[maybe_unused]] ManagedThread *thread, [[maybe_unused]] Frame *frame, ObjectHeader *thisObj,
                 [[maybe_unused]]uint32_t id, [[maybe_unused]] ObjectHeader *val)
{
    if (thisObj == nullptr) {
        interpreter::RuntimeInterface::ThrowNullPointerException();
        return;
    }
    auto *cls = thisObj->ClassAddr<Class>();
    ASSERT(cls != nullptr);
    [[maybe_unused]] auto pf = frame->GetMethod()->GetPandaFile();
    switch (cls->GetSourceLang()) {
% Common::plugins.each_value do |plugin_opts|
        case <%= plugin_opts["lang_enum"] %>:
% if plugin_opts.include?('any')
            return <%= plugin_opts["directive_name"].upcase %>AnyStbyname(thread, thisObj,
                pf->GetStringData(panda_file::File::EntityId(id)), val);
% else
            // Any handlers unimplemented for plugin
            UNREACHABLE();
% end
            break;
% end
        default:
            UNREACHABLE();
    }
}

ObjectHeader *AnyLdbyidx([[maybe_unused]] ManagedThread *thread, ObjectHeader *thisObj,
                         [[maybe_unused]] double idxFloat)
{
    if (thisObj == nullptr) {
        interpreter::RuntimeInterface::ThrowNullPointerException();
        return nullptr;
    }
    auto *cls = thisObj->ClassAddr<Class>();
    ASSERT(cls != nullptr);

    switch (cls->GetSourceLang()) {
% Common::plugins.each_value do |plugin_opts|
        case <%= plugin_opts["lang_enum"] %>:
% if plugin_opts.include?('any')
            return <%= plugin_opts["directive_name"].upcase %>AnyLdbyidx(thread, thisObj, idxFloat);
% else
            // Any handlers unimplemented for plugin
            UNREACHABLE();
% end
            break;
% end
        default:
            // NOTE(nsizov): implement core handler here if needed
            UNREACHABLE();
    }
}

void AnyStbyidx([[maybe_unused]] ManagedThread *thread, ObjectHeader *thisObj, [[maybe_unused]] double key,
                [[maybe_unused]] ObjectHeader *val)
{
    if (thisObj == nullptr) {
        interpreter::RuntimeInterface::ThrowNullPointerException();
        return;
    }
    auto *cls = thisObj->ClassAddr<Class>();
    ASSERT(cls != nullptr);

    switch (cls->GetSourceLang()) {
% Common::plugins.each_value do |plugin_opts|
        case <%= plugin_opts["lang_enum"] %>:
% if plugin_opts.include?('any')
            <%= plugin_opts["directive_name"].upcase %>AnyStbyidx(thread, thisObj, key, val);
% else
            // Any handlers unimplemented for plugin
            UNREACHABLE();
% end
            break;
% end
        default:
            // NOTE(nsizov): implement core handler here if needed
            UNREACHABLE();
    }
}

ObjectHeader *AnyLdbyval([[maybe_unused]] ManagedThread *thread, ObjectHeader *thisObj,
                         [[maybe_unused]] ObjectHeader *key)
{
    if (thisObj == nullptr) {
        interpreter::RuntimeInterface::ThrowNullPointerException();
        return nullptr;
    }
    auto *cls = thisObj->ClassAddr<Class>();
    ASSERT(cls != nullptr);

    switch (cls->GetSourceLang()) {
% Common::plugins.each_value do |plugin_opts|
        case <%= plugin_opts["lang_enum"] %>:
% if plugin_opts.include?('any')
            return <%= plugin_opts["directive_name"].upcase %>AnyLdbyval(thread, thisObj, key);
% else
            // Any handlers unimplemented for plugin
            UNREACHABLE();
% end
            break;
% end
        default:
            // NOTE(nsizov): implement core handler here if needed
            UNREACHABLE();
    }
}

void AnyStbyval([[maybe_unused]] ManagedThread *thread, ObjectHeader *thisObj, [[maybe_unused]] ObjectHeader *key,
                [[maybe_unused]] ObjectHeader *val)
{
    if (thisObj == nullptr) {
        interpreter::RuntimeInterface::ThrowNullPointerException();
        return;
    }
    auto *cls = thisObj->ClassAddr<Class>();
    ASSERT(cls != nullptr);

    switch (cls->GetSourceLang()) {
% Common::plugins.each_value do |plugin_opts|
        case <%= plugin_opts["lang_enum"] %>:
% if plugin_opts.include?('any')
            <%= plugin_opts["directive_name"].upcase %>AnyStbyval(thread, thisObj, key, val);
% else
            // Any handlers unimplemented for plugin
            UNREACHABLE();
% end
            break;
% end
        default:
            // NOTE(nsizov): implement core handler here if needed
            UNREACHABLE();
    }
}

extern "C" bool AnyIsinstance([[maybe_unused]] ManagedThread *thread, ObjectHeader *lhs,
                              [[maybe_unused]] ObjectHeader *rhs)
{
    if (lhs == nullptr) {
        interpreter::RuntimeInterface::ThrowNullPointerException();
        return false;
    }
    auto *cls = lhs->ClassAddr<Class>();
    ASSERT(cls != nullptr);

    switch (cls->GetSourceLang()) {
% Common::plugins.each_value do |plugin_opts|
        case <%= plugin_opts["lang_enum"] %>:
% if plugin_opts.include?('any')
            return <%= plugin_opts["directive_name"].upcase %>AnyIsinstance(thread, lhs, rhs);
% else
            // Any handlers unimplemented for plugin
            UNREACHABLE();
% end
            break;
% end
        default:
            // NOTE(nsizov): implement core handler here if needed
            UNREACHABLE();
    }
}

static inline ObjectHeader *AnyCall([[maybe_unused]] ManagedThread *thread, ObjectHeader *func,
                                    [[maybe_unused]] Span<VMHandle<ObjectHeader>> args)
{
    if (func == nullptr) {
        interpreter::RuntimeInterface::ThrowNullPointerException();
        return nullptr;
    }
    auto *cls = func->ClassAddr<Class>();
    switch (cls->GetSourceLang()) {
% Common::plugins.each_value do |plugin_opts|
        case <%= plugin_opts["lang_enum"] %>:
% if plugin_opts.include?('any')
            return <%= plugin_opts["directive_name"].upcase %>AnyCall(thread, func, args);
% else
            // Any handlers unimplemented for plugin
            UNREACHABLE();
% end
            break;
% end
        default:
            // NOTE(nsizov): implement core handler here if needed
            UNREACHABLE();
    }
}

ObjectHeader *AnyCall0(ManagedThread *thread, ObjectHeader *func)
{
    [[maybe_unused]] HandleScope<ObjectHeader *> scope(thread);
    return AnyCall(thread, func, Span<VMHandle<ObjectHeader>>());
}

ObjectHeader *AnyCallRange(ManagedThread *thread, Frame *frame, ObjectHeader *func,
                           uint8_t argStart, uint8_t argc)
{
    [[maybe_unused]] HandleScope<ObjectHeader *> scope(thread);
    PandaVector<VMHandle<ObjectHeader>> args;
    for (uint8_t i = 0; i < argc; i++) {
        args.emplace_back(VMHandle<ObjectHeader>(thread, frame->GetVReg(argStart + i).template GetAs<ObjectHeader *>()));
    }
    return AnyCall(thread, func, Span<VMHandle<ObjectHeader>>(args));
}

ObjectHeader *AnyCallShort(ManagedThread *thread, ObjectHeader *func, ObjectHeader *arg)
{
    [[maybe_unused]] HandleScope<ObjectHeader *> scope(thread);
    std::array<VMHandle<ObjectHeader>, 1> args = {VMHandle<ObjectHeader>(thread, arg)};
    return AnyCall(thread, func, Span<VMHandle<ObjectHeader>>(args));
}

static inline ObjectHeader *AnyCallThis([[maybe_unused]] ManagedThread *thread, [[maybe_unused]] Frame *frame,
                                        ObjectHeader *thisObj, [[maybe_unused]] uint32_t name,
                                        [[maybe_unused]] Span<VMHandle<ObjectHeader>> args)
{
    if (thisObj == nullptr) {
        interpreter::RuntimeInterface::ThrowNullPointerException();
        return nullptr;
    }
    auto *cls = thisObj->ClassAddr<Class>();
    ASSERT(cls != nullptr);
    [[maybe_unused]] auto pf = frame->GetMethod()->GetPandaFile();
    switch (cls->GetSourceLang()) {
% Common::plugins.each_value do |plugin_opts|
        case <%= plugin_opts["lang_enum"] %>:
% if plugin_opts.include?('any')
            return <%= plugin_opts["directive_name"].upcase %>AnyCallThis(thread, thisObj,
                pf->GetStringData(panda_file::File::EntityId(name)), args);
% else
            // Any handlers unimplemented for plugin
            UNREACHABLE();
% end
            break;
% end
        default:
            // NOTE(nsizov): implement core handler here if needed
            UNREACHABLE();
    }
}

extern "C" ObjectHeader *AnyCallThis0(ManagedThread *thread, Frame *frame, ObjectHeader *thisObj,
                                      uint32_t name)
{
    [[maybe_unused]] HandleScope<ObjectHeader *> scope(thread);
    return AnyCallThis(thread, frame, thisObj, name, Span<VMHandle<ObjectHeader>>());
}

extern "C" ObjectHeader *AnyCallThisRange(ManagedThread *thread, Frame *frame, ObjectHeader *thisObj,
                                          uint32_t name, uint8_t argStart, uint8_t argc)
{
    [[maybe_unused]] HandleScope<ObjectHeader *> scope(thread);
    PandaVector<VMHandle<ObjectHeader>> args;
    for (uint8_t i = 0; i < argc; i++) {
        args.emplace_back(VMHandle<ObjectHeader>(thread, frame->GetVReg(argStart + i).template GetAs<ObjectHeader *>()));
    }
    return AnyCallThis(thread, frame, thisObj, name, Span<VMHandle<ObjectHeader>>(args));
}

extern "C" ObjectHeader *AnyCallThisShort(ManagedThread *thread, Frame *frame, ObjectHeader *thisObj,
                                          uint32_t name, ObjectHeader *arg)
{
    [[maybe_unused]] HandleScope<ObjectHeader *> scope(thread);
    std::array<VMHandle<ObjectHeader>, 1> args = {VMHandle<ObjectHeader>(thread, arg)};
    return AnyCallThis(thread, frame, thisObj, name, Span<VMHandle<ObjectHeader>>(args));
}

static inline ObjectHeader *AnyCallNew([[maybe_unused]] ManagedThread *thread, ObjectHeader *ctor,
                                       [[maybe_unused]] Span<VMHandle<ObjectHeader>> args)
{
    if (ctor == nullptr) {
        interpreter::RuntimeInterface::ThrowNullPointerException();
        return nullptr;
    }
    auto *cls = ctor->ClassAddr<Class>();
    ASSERT(cls != nullptr);

    switch (cls->GetSourceLang()) {
% Common::plugins.each_value do |plugin_opts|
        case <%= plugin_opts["lang_enum"] %>:
% if plugin_opts.include?('any')
            return <%= plugin_opts["directive_name"].upcase %>AnyCallNew(thread, ctor, args);
% else
            // Any handlers unimplemented for plugin
            UNREACHABLE();
% end
            break;
% end
        default:
            // NOTE(nsizov): implement core handler here if needed
            UNREACHABLE();
    }
}

extern "C" ObjectHeader *AnyCallNew0(ManagedThread *thread, ObjectHeader *ctor)
{
    [[maybe_unused]] HandleScope<ObjectHeader *> scope(thread);
    return AnyCallNew(thread, ctor, Span<VMHandle<ObjectHeader>>());
}

extern "C" ObjectHeader *AnyCallNewRange(ManagedThread *thread, Frame *frame, ObjectHeader *ctor,
                                         uint8_t argStart, uint8_t argc)
{
    [[maybe_unused]] HandleScope<ObjectHeader *> scope(thread);
    PandaVector<VMHandle<ObjectHeader>> args;
    for (uint8_t i = 0; i < argc; i++) {
        args.emplace_back(VMHandle<ObjectHeader>(thread, frame->GetVReg(argStart + i).template GetAs<ObjectHeader *>()));
    }
    return AnyCallNew(thread, ctor, Span<VMHandle<ObjectHeader>>(args));
}

extern "C" ObjectHeader *AnyCallNewShort(ManagedThread *thread, ObjectHeader *ctor, ObjectHeader *arg)
{
    [[maybe_unused]] HandleScope<ObjectHeader *> scope(thread);
    std::array<VMHandle<ObjectHeader>, 1> args = {VMHandle<ObjectHeader>(thread, arg)};
    return AnyCallNew(thread, ctor, Span<VMHandle<ObjectHeader>>(args));
}
}  // namespace ark::intrinsics

#endif  // CORE_ANY_INTRINSICS_INL